<?php

class Country_Widget_AllVideosController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
   
    $authorizationCore = Engine_Api::_()->authorization();
    // Prepare
    $viewer = Engine_Api::_()->user()->getViewer();
    // Permissions
    $this->view->can_create = $authorizationCore->isAllowed('video', $viewer, 'create');
        
    // Make form
    // Note: this code is duplicated in the video.browse-search widget
    //$this->view->form = $form = new Video_Form_Search();
    
    // Process form
    /*if( $form->isValid($this->_getAllParams()) ) {
      $values = $form->getValues();
    } else {
      $values = array();
    }
    $this->view->formValues = $values;
*/
    $values['status'] = 1;
    $values['search'] = 1;

    $this->view->category = @$values['category'];
    $this->view->text = @$values['text'];


    if( !empty($values['tag']) ) {
      $this->view->tag = Engine_Api::_()->getItem('core_tag', $values['tag'])->text;
    }
    
    // check to see if request is for specific user's listings
    $user_id = $this->_getParam('user');
    if( $user_id ) {
      $values['user_id'] = $user_id;
    }

    // Get videos
    $videoT = Engine_Api::_()->getDbtable("videos","country");
    $select = $videoT->getSellectAllVideoOfCountry($subject->country_id);
    
    $this->view->paginator = $paginator = Zend_Paginator::factory($select);
    $items_count = (int) Engine_Api::_()->getApi('settings', 'core')->getSetting('video.page', 20);
    $paginator->setItemCountPerPage($items_count);
    $paginator->setCurrentPageNumber($this->_getParam('page', 1));

    
  }
}